package util;
/*
    JDBC操作工具类
 */

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class JDBCUtils {
    //1.私有构造方法
    private JDBCUtils(){}

    //2.声明配置信息变量
    private static String DRIVER_CLASS = "com.mysql.cj.jdbc.Driver";
    // 数据库连接信息
    private static final String JDBC_URL = "jdbc:mysql://127.0.0.1:3306/animal_manage";
    private static final String USERNAME = "root";
    private static final String PASSWORD = "operzADF2020qwer";

    private static Connection con;

    //注册数据驱动
    static{
        try{


            //注册驱动
            Class.forName(DRIVER_CLASS);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    //4.获取数据库连接的方法
    public static Connection getConnection() {
        try {
            con = DriverManager.getConnection(JDBC_URL,USERNAME,PASSWORD);
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return con;
    }

}